/* 
* Copyright (C) 2011-2018 ShenZhen iBOXSaaS Information Technology Co.,Ltd. 
* 
* All right reserved. 
* 
* This software is the confidential and proprietary 
* information of iBOXSaaS Company of China. 
* ("Confidential Information"). You shall not disclose 
* such Confidential Information and shall use it only 
* in accordance with the terms of the contract agreement 
* you entered into with iBOXSaaS inc. 
* 
*/

package com.iboxpay.open.gateway.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.web.ZuulHandlerMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.iboxpay.open.common.db.dao.HealthCheckDao;
import com.iboxpay.open.gateway.basedata.BaseData;
import com.iboxpay.open.gateway.event.RefreshRouteService;

import lombok.extern.log4j.Log4j;

/**
 * 
 * RoutesController.java
 * @author xuxiao
 * @date 2018/06/15
 */
@RestController
@Log4j
public class RoutesController {

	@Autowired
	RefreshRouteService refreshRouteService;

	@Autowired
	ZuulHandlerMapping zuulHandlerMapping;
	
	@Autowired
	private HealthCheckDao healthCheckDao;
	
	@Autowired
	private BaseData baseData;
	
	@RequestMapping("/healthCheck")
	public String healthCheck() {
	    healthCheckDao.healthCheck();
	    return "{\"resultCode\":\"0\"}";
	}

	@RequestMapping("/refreshBaseData")
	public String refreshBaseData() {
	    baseData.init();
		return "{\"resultCode\":\"0\"}";
	}
	
	@RequestMapping("/refreshRoute")
	public String refreshRoute() {
	    refreshRouteService.refreshRoute();
	    return "{\"resultCode\":\"0\"}";
	}

	@RequestMapping("/watchNowRoute")
	public String watchNowRoute() {
		Map<String, Object> handlerMap = zuulHandlerMapping.getHandlerMap();
		log.info(handlerMap);
		return "{\"resultCode\":\"0\"}";
	}
}
